#pragma once

#include "RBTree.h"

template <class K, class V>
class map
{
	typedef pair<K, V> T;

	class MapKey
	{
	public:
		const V& operator()(const T& v)
		{
			return v.first;
		}
	};
public:
	typedef typename RBTree<K, T, MapKey>::iterator iterator;
	typedef typename RBTree<const K, const T, const MapKey>::iterator const_iterator;
	const_iterator begin() const
	{
		return _t.begin();
	}

	const_iterator end() const
	{
		return _t.end();
	}

	iterator begin()
	{
		return _t.begin();
	}

	iterator end()
	{
		return _t.end();
	}

	pair<iterator, bool> insert(const pair<K, V>& kv)
	{
		return _t.insert(kv);
	}

	size_t size()
	{
		return _t.size();
	}

	V& operator[](const K& k)
	{
		pair<iterator, bool> ret = _t.insert(make_pair(k, V()));
		return ret.first->second;
	}

	iterator find(const K& k)
	{
		return _t.find(k);
	}

	bool isok()
	{
		return _t.IsRBTree();
	}
	
private:
	RBTree<K, T, MapKey> _t;
};